﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web;

namespace CommandWeb.Framework
{
    public class CommandWebHandler:IHttpHandler
    {
        private IEnumerable<Type> _commands;

        public CommandWebHandler()
        {
            LoadCommands();
        }

  

        private void LoadCommands()
        {
            var enumerable = AppDomain.CurrentDomain.GetAssemblies();
            _commands = enumerable.SelectMany(x => x.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(CommandWeb.Framework.ICommand))));
        }

        public void ProcessRequest(HttpContext context)
        {
            new CommandInvoker(context).Invoke(_commands);
        }

        public bool IsReusable
        {
            get { return true; }
        }
    }
}
